package com.luych.toolbox.common.event.base.service.publisher;

import com.luych.toolbox.common.event.base.service.WebSocketEventRemoteApplicationEvent;
import com.luych.toolbox.common.feign.param.gateway.center.WebSocketEvent;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;

public class WebSocketEventPublisher {

    private final BusProperties busProperties;
    private final ApplicationEventPublisher applicationEventPublisher;

    public WebSocketEventPublisher(BusProperties busProperties, ApplicationEventPublisher applicationEventPublisher) {
        this.busProperties = busProperties;
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void send(WebSocketEvent event) {
        applicationEventPublisher.publishEvent(new WebSocketEventRemoteApplicationEvent(busProperties.getId(), "**", event));
    }
}
